<!-- 深度优先遍历 -->
<script>
  const tree = {
    val: 'a',
    children: [
      {
        val: 'b',
        children: [
          {
            val: 'd',
            children: [],
          },
          {
            val: 'e',
            children: [],
          },
        ],
      },
      {
        val: 'c',
        children: [
          {
            val: 'f',
            children: [],
          },
          {
            val: 'g',
            children: [],
          },
        ],
      },
    ],
  }
  //深度优先递归版
  const dfs = (root) => {
    if (!root) return
    console.log(root.val)
    root.children.forEach(dfs)
  }
  dfs(tree)
</script>
